package com.nineclock.sign.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.enums.ResponseEnum;
import com.nineclock.common.exception.NcException;
import com.nineclock.common.threadlocal.CurrentUserHolder;
import com.nineclock.common.utils.BeanHelper;
import com.nineclock.common.utils.DateTimeUtil;
import com.nineclock.sign.dto.SignAllUserDTO;
import com.nineclock.sign.dto.SignDTO;
import com.nineclock.sign.dto.SignInfoDTO;
import com.nineclock.sign.dto.SignPCListDTO;
import com.nineclock.sign.mapper.SignInfoMapper;
import com.nineclock.sign.mapper.SignPictureMapper;
import com.nineclock.sign.pojo.SignInfo;
import com.nineclock.sign.pojo.SignPicture;
import com.nineclock.sign.service.SignService;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.dto.SysDepartmentDTO;
import com.nineclock.system.feign.OrganizationFeign;
import com.nineclock.system.feign.SysUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Service
@Slf4j
public class SignServiceImpl implements SignService {

    @Autowired
    SignInfoMapper signInfoMapper;

    @Autowired
    SysUserFeign sysUserFeign;

    @Autowired
    OrganizationFeign organizationFeign;

    @Autowired
    RedisTemplate<String, String> redisTemplate;

    @Autowired
    SignPictureMapper signPictureMapper;

    @Override
    public void export(String startTime, String endTime) throws IOException {

        List<SignPCListDTO> signPCListDTOS = this.querySignListRecord(startTime, endTime);


        //. 获取响应对象，并设置 响应对象
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
        HttpServletResponse response = servletRequestAttributes.getResponse();
        response.setHeader("Content-disposition", "attachment;filename=Attendance.xlsx");
        response.setContentType("application/octet-stream;charset=UTF-8");
        response.setCharacterEncoding("utf-8");


        // *************easyExcel **********

        WriteCellStyle cellStyle = new WriteCellStyle();
        //表头和内容都是水平居中
        cellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);

        //设置字体
        WriteFont font = new WriteFont();
        font.setFontName("宋体");
        font.setFontHeightInPoints((short) 12);
        cellStyle.setWriteFont(font);

        HorizontalCellStyleStrategy styleStrategy = new HorizontalCellStyleStrategy(cellStyle, cellStyle);

        EasyExcel.write(response.getOutputStream())
                .head(handlerHead(signPCListDTOS))
                .registerWriteHandler(styleStrategy)
                .registerWriteHandler(new MyColumnStyle())
                .sheet("测试数据")
                .doWrite(handlerData(signPCListDTOS));

        // *************easyExcel **********
    }

    //操作数据
    private List<List<String>> handlerData(List<SignPCListDTO> signPCListDTOS) {
        List<List<String>> data = new ArrayList<>();
        //循环 每一个 员工
        for (SignPCListDTO signPCListDTO : signPCListDTOS) {
            List<String> list = new ArrayList<>();
            list.add(signPCListDTO.getUsername());
            list.add(signPCListDTO.getWorkNumber());
            list.add(signPCListDTO.getDepartment().getName());
            list.add(signPCListDTO.getPost());
            //取出 员工每天的考勤状态
            List<SignInfoDTO> signs = signPCListDTO.getSigns();
            for (SignInfoDTO signInfoDTO : signs) {
                list.add(signInfoDTO.getSignCount().toString());
            }


            //添加到data中
            data.add(list);

        }

        return data;
    }

    /**
     * 操作表头
     *
     * @return
     */
    private List<List<String>> handlerHead(List<SignPCListDTO> signPCListDTOS) {
        List<List<String>> head = new ArrayList<>();
        head.add(Arrays.asList("姓名"));
        head.add(Arrays.asList("工号"));
        head.add(Arrays.asList("部门"));
        head.add(Arrays.asList("职位"));
        //获取集合中的第一个对象
        //获取了第一个员工的每天打卡情况 对应 日期
        SignPCListDTO signPCListDTO = signPCListDTOS.get(0);
        List<SignInfoDTO> signs = signPCListDTO.getSigns();
        for (SignInfoDTO sign : signs) {
            head.add(Arrays.asList(sign.getSignDate()));
        }
        return head;
    }

    class MyColumnStyle extends AbstractColumnWidthStyleStrategy {

        @Override
        protected void setColumnWidth(WriteSheetHolder writeSheetHolder,
                                      List<CellData> cellDataList,
                                      Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
            writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), 4500);
        }
    }

    /**
     * 分页查询签到列表
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return pageResult
     * Long total;
     * Long totalPage;
     * List<SignPCListDTO> rows;
     */

    public List<SignPCListDTO> querySignListRecord(String startTime, String endTime) {
        if (startTime == null || endTime == null) {
            throw new NcException(ResponseEnum.INVALID_PARAM_ERROR);
        }
        //分页查询返回对象
        PageResult<SignPCListDTO> pageResult = new PageResult<>();

        //分页查询条件 公司id 前端传递时间范围内
        LambdaQueryWrapper<SignInfo> signWrapper = new LambdaQueryWrapper<>();
        signWrapper.eq(SignInfo::getCompanyId, CurrentUserHolder.get().getCompanyId());
        signWrapper.between(SignInfo::getCreateDate, startTime, endTime);

        //有效的签到记录
        List<SignInfo> records = signInfoMapper.selectList(signWrapper);

        List<SignPCListDTO> list = new ArrayList<>();

        //签到记录 每一个人在一天中可打多次卡
        Map<Long, List<SignInfo>> collect = records.stream().collect(Collectors.groupingBy(SignInfo::getCompanyUserId));

        //根据当前线程companyUserId 查询整个企业的用户
        List<SysCompanyUserDTO> userList = organizationFeign.queryAllCompanyUser().getData();

        for (SysCompanyUserDTO sysCompanyUserDTO : userList) {
            //签到id 用户名称 工号 职位 部门（sysDepartmentDto） 签到信息（List<SignInfoDto>）
            SignPCListDTO signPCListDTO = new SignPCListDTO();

            //获取每一个用户公司用户id
            Long companyUserId = sysCompanyUserDTO.getUserId();

            //远程调用 获取SysCompanyUserDTO
            List<SysCompanyUserDTO> data = sysUserFeign.queryCompanyUser(CurrentUserHolder.get().getCompanyId(), companyUserId).getData();

            //赋值username
            signPCListDTO.setUsername(data.get(0).getUserName());

            //赋值workNumber
            signPCListDTO.setWorkNumber(data.get(0).getWorkNumber());

            //赋值post
            signPCListDTO.setPost(data.get(0).getPost());

            //赋值部门
            SysDepartmentDTO sysDepartmentDTO = new SysDepartmentDTO();
            sysDepartmentDTO.setName(data.get(0).getDepartmentName());
            sysDepartmentDTO.setId(data.get(0).getDepartmentId());
            signPCListDTO.setDepartment(sysDepartmentDTO);

            //赋值签到信息 签到信息为空
            if (CollectionUtil.isEmpty(collect)) {
                List<SignInfoDTO> signs = new ArrayList<>();
                // 获取 日期区间内时间列表
                List<Date> dateList = DateTimeUtil.getDatesBetweenTwoDate(startTime, endTime, "yyyy-MM-dd");
                //把日期列表 转换为 日期字符串列表
                List<String> dateStrList = dateList.stream().map(date -> {
                    return DateTimeUtil.dateToStr(date, "yyyy-MM-dd");
                }).collect(Collectors.toList());
                for (String time : dateStrList) {
                    SignInfoDTO signInfoDTO = new SignInfoDTO();
                    signInfoDTO.setSignDate(time);
                    signInfoDTO.setSignCount(0);
                    signs.add(signInfoDTO);
                }
                signPCListDTO.setSigns(signs);
            } else {
                List<SignInfoDTO> signs = new ArrayList<>();
                // 获取 日期区间内时间列表
                List<Date> dateList = DateTimeUtil.getDatesBetweenTwoDate(startTime, endTime, "yyyy-MM-dd");
                //把日期列表 转换为 日期字符串列表
                List<String> dateStrList = dateList.stream().map(date -> {
                    return DateTimeUtil.dateToStr(date, "yyyy-MM-dd");
                }).collect(Collectors.toList());
                for (String time : dateStrList) {
                    SignInfoDTO signInfoDTO = new SignInfoDTO();
                    signInfoDTO.setSignDate(time);
                    signInfoDTO.setSignCount(0);
                    for (Map.Entry<Long, List<SignInfo>> userEntry : collect.entrySet()) {
                        //赋值签到信息
                        if (userEntry.getKey().equals(sysCompanyUserDTO.getId())){
                            Map<String, List<SignInfo>> dateCollect = userEntry.getValue().stream().collect(Collectors.groupingBy(SignInfo::getCreateDate));
                            for (Map.Entry<String, List<SignInfo>> stringListEntry : dateCollect.entrySet()) {
                                if (time.equals(stringListEntry.getKey())) {
                                    if (CollectionUtil.isNotEmpty(stringListEntry.getValue())) {
                                        signInfoDTO.setSignCount(stringListEntry.getValue().size());
                                    }
                                }
                            }
                        }
                    }
                    signs.add(signInfoDTO);
                }
                signPCListDTO.setSigns(signs);
            }
            list.add(signPCListDTO);
        }
//对象赋值
        return list;
    }

    /**
     * 分页查询签到列表
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param page      第几页
     * @param pageSize  一页显示个数
     * @return pageResult
     * Long total;
     * Long totalPage;
     * List<SignPCListDTO> rows;
     */
    @Override
    public PageResult querySignListRecord(String startTime, String endTime, Integer page, Integer pageSize) {
        if (startTime == null || endTime == null || page == null || pageSize == null) {
            throw new NcException(ResponseEnum.INVALID_PARAM_ERROR);
        }
        //分页查询返回对象
        PageResult<SignPCListDTO> pageResult = new PageResult<>();

        //分页查询条件 公司id 前端传递时间范围内
        LambdaQueryWrapper<SignInfo> signWrapper = new LambdaQueryWrapper<>();
        signWrapper.eq(SignInfo::getCompanyId, CurrentUserHolder.get().getCompanyId());
        signWrapper.between(SignInfo::getCreateDate, startTime, endTime);

        //有效的签到记录
        List<SignInfo> records = signInfoMapper.selectList(signWrapper);

        List<SignPCListDTO> list = new ArrayList<>();

        //签到记录 每一个人在一天中可打多次卡
        Map<Long, List<SignInfo>> collect = records.stream().collect(Collectors.groupingBy(SignInfo::getCompanyUserId));

        //根据当前线程companyUserId 查询整个企业的用户
        List<SysCompanyUserDTO> userList = organizationFeign.membersUser(page, pageSize).getData().getRows();

        for (SysCompanyUserDTO sysCompanyUserDTO : userList) {
            //签到id 用户名称 工号 职位 部门（sysDepartmentDto） 签到信息（List<SignInfoDto>）
            SignPCListDTO signPCListDTO = new SignPCListDTO();

            //获取每一个用户公司用户id
            Long companyUserId = sysCompanyUserDTO.getUserId();

            //远程调用 获取SysCompanyUserDTO
            List<SysCompanyUserDTO> data = sysUserFeign.queryCompanyUser(CurrentUserHolder.get().getCompanyId(), companyUserId).getData();

            //赋值username
            signPCListDTO.setUsername(data.get(0).getUserName());

            //赋值workNumber
            signPCListDTO.setWorkNumber(data.get(0).getWorkNumber());

            //赋值post
            signPCListDTO.setPost(data.get(0).getPost());

            //赋值部门
            SysDepartmentDTO sysDepartmentDTO = new SysDepartmentDTO();
            sysDepartmentDTO.setName(data.get(0).getDepartmentName());
            sysDepartmentDTO.setId(data.get(0).getDepartmentId());
            signPCListDTO.setDepartment(sysDepartmentDTO);

            //赋值签到信息 签到信息为空
            if (CollectionUtil.isEmpty(collect)) {
                List<SignInfoDTO> signs = new ArrayList<>();
                // 获取 日期区间内时间列表
                List<Date> dateList = DateTimeUtil.getDatesBetweenTwoDate(startTime, endTime, "yyyy-MM-dd");
                //把日期列表 转换为 日期字符串列表
                List<String> dateStrList = dateList.stream().map(date -> {
                    return DateTimeUtil.dateToStr(date, "yyyy-MM-dd");
                }).collect(Collectors.toList());
                for (String time : dateStrList) {
                    SignInfoDTO signInfoDTO = new SignInfoDTO();
                    signInfoDTO.setSignDate(time);
                    signInfoDTO.setSignCount(0);
                    signs.add(signInfoDTO);
                }
                signPCListDTO.setSigns(signs);
            } else {
                List<SignInfoDTO> signs = new ArrayList<>();
                // 获取 日期区间内时间列表
                List<Date> dateList = DateTimeUtil.getDatesBetweenTwoDate(startTime, endTime, "yyyy-MM-dd");
                //把日期列表 转换为 日期字符串列表
                List<String> dateStrList = dateList.stream().map(date -> {
                    return DateTimeUtil.dateToStr(date, "yyyy-MM-dd");
                }).collect(Collectors.toList());
                for (String time : dateStrList) {
                    SignInfoDTO signInfoDTO = new SignInfoDTO();
                    signInfoDTO.setSignDate(time);
                    signInfoDTO.setSignCount(0);
                    for (Map.Entry<Long, List<SignInfo>> userEntry : collect.entrySet()) {
                        //赋值签到信息
                        if (userEntry.getKey().equals(sysCompanyUserDTO.getId())) {
                            Map<String, List<SignInfo>> dateCollect = userEntry.getValue().stream().collect(Collectors.groupingBy(SignInfo::getCreateDate));
                            for (Map.Entry<String, List<SignInfo>> stringListEntry : dateCollect.entrySet()) {
                                if (time.equals(stringListEntry.getKey())) {
                                    if (CollectionUtil.isNotEmpty(stringListEntry.getValue())) {
                                        signInfoDTO.setSignCount(stringListEntry.getValue().size());
                                    }
                                }
                            }
                        }
                    }
                    signs.add(signInfoDTO);
                }
                signPCListDTO.setSigns(signs);
            }
            list.add(signPCListDTO);
        }
        //对象赋值
        pageResult.setRows(list);
        pageResult.setTotal(organizationFeign.membersUser(page, pageSize).getData().getTotal());
        pageResult.setTotalPage(organizationFeign.membersUser(page, pageSize).getData().getTotalPage());
        return pageResult;
    }


    /**
     * @description: 签到: 移动端签到
     * @param: signDTO
     * @return: void
     * @author 菜鸟
     * @date: 2021/7/23
     */
    @Override
    public void sign(SignDTO signDTO) throws ParseException {
        if (signDTO == null) {
            throw new NcException(ResponseEnum.INVALID_PARAM_ERROR);
        }

        SignInfo signInfo = BeanHelper.copyProperties(signDTO, SignInfo.class);

//        设置基础字段
        Long companyUserId = CurrentUserHolder.get().getCompanyUserId();
        signInfo.setCompanyUserId(companyUserId);
        signInfo.setCompanyId(CurrentUserHolder.get().getCompanyId());
        signInfo.setCreateTime(new Date());
        signInfo.setCreateDate(DateTimeUtil.dateToStr(new Date(), "yyyy-MM-dd"));
        signInfo.setCreateMonth(DateTimeUtil.dateToStr(new Date(), "yyyy-MM"));

        signInfoMapper.insert(signInfo);

        SignPicture signPicture = new SignPicture();
        signPicture.setSignId(signInfo.getId());
        signPicture.setUrl(signDTO.getImages());
        signPictureMapper.insert(signPicture);


//        将其放入redis中存储(当月)
        Long userId = CurrentUserHolder.get().getId();
        String key = DateTimeUtil.dateToStr(new Date(), "yyyy-MM") + userId;
        String times = 0 + "";
        redisTemplate.boundValueOps(key).set(times, Integer.parseInt(times) + 1);

// 过期
//        DateTimeUtil.dateToStr(new Date(),"yyyy-MM"),DateTimeUtil.getCurrentMonthLastDay(),distanceDay(new Date(),)
        redisTemplate.opsForValue().set(key, times, getNowToNextMonthSeconds(), TimeUnit.DAYS);
//        redisTemplate.opsForValue().

//        将其放入redis中存储(当日)
        String keyDay = DateTimeUtil.dateToStr(new Date(), "yyyy-MM-dd") + userId;
        String timeDay = 0 + "";
        redisTemplate.boundValueOps(keyDay).set(timeDay, Integer.parseInt(times) + 1);

        // 过期
        redisTemplate.opsForValue().set(keyDay, timeDay, getNowToNextDaySeconds(), TimeUnit.SECONDS);
    }

    /**
     * @description: 当日打卡次数
     * @param:
     * @return: java.lang.Integer
     * @author 菜鸟
     * @date: 2021/7/23
     */
    @Override
    public Integer getDayCount() {
        LambdaQueryWrapper<SignInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SignInfo::getCompanyId, CurrentUserHolder.get().getCompanyId());
        queryWrapper.eq(SignInfo::getCompanyUserId, CurrentUserHolder.get().getCompanyId());
        String dateToStr = DateTimeUtil.dateToStr(new Date(), "yyyy-MM-dd");
        queryWrapper.eq(SignInfo::getCreateDate, dateToStr);
        return signInfoMapper.selectCount(queryWrapper);
    }


    /**
     * 获取团队员工打卡列表
     *
     * @param dateStr
     * @return
     */
    @Override
    public List<SignAllUserDTO> getListSignAllUser(String dateStr) {
        if (StrUtil.isEmpty(dateStr)) {
            throw new NcException(ResponseEnum.INVALID_PARAM_ERROR);
        }

        //查看当前用户所属团队
        Long departmentId = CurrentUserHolder.get().getDepartmentId();
        //员工编号
        Long companyUserId = CurrentUserHolder.get().getCompanyUserId();

        //查询当前员工所在部门集合
        List<Long> departIds = organizationFeign.queryDepartmentsByUserId(companyUserId).getData();

        if (CollectionUtil.isEmpty(departIds)) {
            throw new NcException(ResponseEnum.INVALID_PARAM_ERROR);
        }

        //获取部门下员工编号集合
        List<Long> userIds = organizationFeign.queryUserIdByDepartmentIds(departIds).getData();

        //查询当天日期下所属团队成员的打卡情况
        return getSignAllUserDto(userIds, dateStr);

    }

    /**
     * 查询用户某一天的签到记录
     *
     * @param userIds
     * @param dateStr
     * @return
     */
    private List<SignAllUserDTO> getSignAllUserDto(List<Long> userIds, String dateStr) {

        List<SignAllUserDTO> list = new ArrayList<>();

        //某个员工指定日期下的所有签到记录
        for (Long userId : userIds) {
            LambdaQueryWrapper<SignInfo> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SignInfo::getCompanyId, CurrentUserHolder.get().getCompanyId());    //企业
            queryWrapper.eq(SignInfo::getCreateDate, dateStr);        //查询日期
            queryWrapper.eq(SignInfo::getCompanyUserId,userId);
            Map<Long, List<SignInfo>> map = signInfoMapper.selectList(queryWrapper).stream().collect(Collectors.groupingBy(SignInfo::getCompanyUserId));

            Set<Long> keySet = map.keySet();


            for (Long id : keySet) {
                SignAllUserDTO signAllUserDTO = new SignAllUserDTO();
                List<SignDTO> signDTOS = BeanHelper.copyWithCollection(map.get(id), SignDTO.class);
                //封装SignDTO数据
                //设置用户名
                SysCompanyUserDTO userDTO = sysUserFeign.queryCompanyUserById(id).getData();
                signAllUserDTO.setUsername(userDTO.getUserName());

                //查询图片地址列表
                List<String> prictureList = null;
                for (SignDTO signDTO : signDTOS) {
                    LambdaQueryWrapper<SignPicture> pictureWrapper = new LambdaQueryWrapper<>();
                    pictureWrapper.eq(SignPicture::getSignId, signDTO.getId());
                    //签到图片集合
                    prictureList = signPictureMapper.selectList(pictureWrapper).stream().map(SignPicture::getUrl).collect(Collectors.toList());
                    signDTO.setSignPictureUrlList(prictureList);

                    //设置用户名
                    signDTO.setUserName(userDTO.getUserName());

                    String str = StrUtil.join("-", prictureList);
                    //设置查询到的签到图片
                    signDTO.setImages(str);
                    //设置当月签到次数
                    signDTO.setDayCount(signDTOS.size() + "");

                    LambdaQueryWrapper<SignInfo> countQwrapper = new LambdaQueryWrapper<>();
                    countQwrapper.eq(SignInfo::getCompanyId, CurrentUserHolder.get().getCompanyId());
                    countQwrapper.eq(SignInfo::getCompanyUserId, CurrentUserHolder.get().getCompanyUserId());
                    countQwrapper.eq(SignInfo::getCreateMonth, signDTO.getCreateMonth());
                    Integer count = signInfoMapper.selectCount(countQwrapper);
                    //设置当月签到次数
                    signDTO.setMonthCount(count + "");
                }

                signAllUserDTO.setSignResponseList(signDTOS);
                list.add(signAllUserDTO);
            }

        }

        return list;
    }





    /**
     * 计算第二天凌晨与当前时间的时间差秒数
     *
     * @param
     * @return java.lang.Long
     * @author shy
     * @date 2021/3/12 18:10
     */
    public static Long getNowToNextDaySeconds() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000;
    }

    public static Long getNowToNextMonthSeconds() throws ParseException {
        String monthLastDay = DateTimeUtil.getCurrentMonthLastDay();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = simpleDateFormat.parse(monthLastDay);
//        long time = date.getTime();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return (calendar.getTimeInMillis() - System.currentTimeMillis()) / 1000;
    }
// TODO  一个月过期一次


    @Override
    public List<SignDTO> queryHistory(String dateStr) {
        //获取到用户id
         Long companyUserId = CurrentUserHolder.get().getCompanyUserId();
//        ArrayList<SignDTO> list = new ArrayList<>();
        //获取本月打卡次数
        String mouthCount =  redisTemplate.boundValueOps(DateTimeUtil.dateToStr(new Date(), "yyyy-MM") + companyUserId).get();

        //获取员工每天的打卡信息
        LambdaQueryWrapper<SignInfo> wrapper = new LambdaQueryWrapper<>();
        //因为不知道员工何时打卡的所以不需要get员工的打卡id    wrapper.eq(SignInfo::getId, CurrentUserHolder.get().getId());
        wrapper.eq(SignInfo::getCompanyUserId, companyUserId);
        wrapper.eq(SignInfo::getCreateMonth, dateStr);


        //mapper对接数据库查询里面的信息
        List<SignInfo> signInfos = signInfoMapper.selectList(wrapper);


        //做代码健壮性判断
        if (signInfos == null) {
            throw new NcException(ResponseEnum.DATA_NOT_EXISTS);
        }
        //        把得到的打卡信息发送给前端所需要转换为DTO对象
        List<SignDTO> signDTOS = BeanHelper.copyWithCollection(signInfos, SignDTO.class);

        //遍历打卡信息所在的集合，获取到里面的具体数据
        for (SignDTO signDTO : signDTOS) {
            LambdaQueryWrapper<SignPicture> wrapper1 = new LambdaQueryWrapper<>();
            wrapper1.eq(SignPicture::getSignId, signDTO.getId());
            List<SignPicture> signPictures = signPictureMapper.selectList(wrapper1);
            List<String> pictures = signPictures.stream().map(s -> {
                return s.getUrl();
            }).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(pictures)){
                signDTO.setSignPictureUrlList(pictures);
                String join = StrUtil.join(",", pictures);
                signDTO.setImages(join);

            }
            signDTO.setMonthCount(mouthCount);

            SysCompanyUserDTO data = sysUserFeign.queryCompanyUserById(signDTO.getCompanyUserId()).getData();
            signDTO.setUserName(data.getUserName());
            String dayCount =  redisTemplate.boundValueOps(signDTO.getCreateDate() + companyUserId).get();
            signDTO.setDayCount(dayCount);

        }
        return signDTOS;
    }
}
